package com.itcast.demo11;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class Demo01 {
    volatile static int count =0;
   static Object o = new Object();
    public static void main(String[] args) throws InterruptedException {

        ExecutorService executorService = Executors.newCachedThreadPool();
        AtomicInteger a = new AtomicInteger();
//            for (int i = 0; i < 100; i++) {
//                executorService.submit(()-> {
//                            while (true) {
//                                synchronized (o) {
//                                    count++;
//                                    //  int i1 = a.incrementAndGet();
//                                    try {
//                                        Thread.sleep(100);
//                                    } catch (InterruptedException e) {
//                                        e.printStackTrace();
//                                    }
//                                    if (count >= 100) {
//                                        break;
//                                    }
//                                    System.out.println(Thread.currentThread().getName() + "hah" + count);
//                                }
//                                //  }
//                            }
//                        }
//            }

    Thread.sleep(1000);
System.out.println(a.get());
System.out.println(a.get());
System.out.println(a.get());
System.out.println(a.get());
System.out.println(a.get());
System.out.println(a.get());
System.out.println(a.get());
executorService.shutdown();

    }
    }


